/*
 * Copyright 2002-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.transaction;

import java.io.Flushable;

/**
 * Representation of the status of a transaction.
 *
 * <p>Transactional code can use this to retrieve status information,
 * and to programmatically request a rollback (instead of throwing
 * an exception that causes an implicit rollback).
 *
 * <p>Includes the {@link SavepointManager} interface to provide access
 * to savepoint management facilities. Note that savepoint management
 * is only available if supported by the underlying transaction manager.
 *
 * @author Juergen Hoeller
 * @since 27.03.2003
 * @see #setRollbackOnly()
 * @see PlatformTransactionManager#getTransaction
 * @see org.springframework.transaction.support.TransactionCallback#doInTransaction
 * @see org.springframework.transaction.interceptor.TransactionInterceptor#currentTransactionStatus()
 *
 * 代表一个事务的具体运行状态、以及还原点
 * 若有需要，事务代码可以使用它来检索状态信息，以编程方式请求回滚（而不是抛出导致隐式回滚的异常）
 * 可以看到它继承自SavepointManager，所以它也会处理还原点
 */
public interface TransactionStatus extends SavepointManager, Flushable {
	/**
	 * 判断当前的事务是否是新事务
	 */
	boolean isNewTransaction();
	/**
	 * 判断该事务里面是否含有还原点
	 */
	boolean hasSavepoint();
	/**
	 * 标识位：true 表示事务的唯一结果是进行回滚。
	 * 因此如果你在外层给try catch住不让事务回滚，就会抛出你可能常见的异常
	 */
	void setRollbackOnly();

	/**
	 *  返回事务是否已标记为仅回滚 用于嵌套事务处理内层事务
	 * @return
	 */
	boolean isRollbackOnly();
	/**
	 * 将基础会话刷新到数据存储
	 */
	@Override
	void flush();
	/**
	 * 标识位：true 表示本次事务已经完成
	 * 不管是commit或者rollback了都算结束了~~~
	 */
	boolean isCompleted();

}
